<?php
if($_POST['submit_test']!=true) echo "";
	else{
	   $sel_u = mysql_query('SELECT teacher_to FROM users WHERE username="'.$_SESSION['username'].'"');
	   $row_u = mysql_fetch_assoc($sel_u);
	   
	   $test_name=trim(addslashes(htmlspecialchars($_POST['test_name'])));
	   $test_descr=trim(addslashes(htmlspecialchars($_POST['test_descr'])));
	   $date_added=time();
	   $from_who=$_SESSION['username'];
	   $module = $row_u['teacher_to'];
	   
	   if(empty($test_name) || empty($test_descr)){
	      echo '<p class="error">Моля, попълнете всички полета!</p>';
	   }
	   else{
	      if(strlen($test_name)<3 || strlen($test_descr)<3){
		     echo '<p class="error">Кратко име и/или описание на теста!</p>';
		  } else {
          $select_test='SELECT test_name FROM test WHERE test_name="'.$test_name.'"';
		  $res_test=mysql_query($select_test);
		  
		  if(mysql_num_rows($res_test)!=0){
		  echo '<p class="error">Името на теста е заето!</p>';
		  }
		  else{
		  $ins_test='INSERT INTO test(test_name, test_descr, date_added, from_who, module) VALUES("'.$test_name.'","'.$test_descr.'","'.$date_added.'","'.$from_who.'", "'.$module.'")';
		  $res_ins_test=mysql_query($ins_test);
		  echo '<p class="success">Успешен запис!</p>';
		  }
		  }
	   }
	}
?>